
package me.zhengjie.modules.workOrder.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.workOrder.domain.WorkOrderHead;
import me.zhengjie.modules.workOrder.service.WorkOrderHeadService;
import me.zhengjie.modules.workOrder.service.dto.WorkOrderHeadQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://eladmin.vip
* @author 李奎
* @date 2023-06-29
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "workOrder管理")
@RequestMapping("/api/workOrderHead")
public class WorkOrderHeadController {

    private final WorkOrderHeadService workOrderHeadService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('workOrderHead:list')")
    public void exportWorkOrderHead(HttpServletResponse response, WorkOrderHeadQueryCriteria criteria) throws IOException {
        workOrderHeadService.download(workOrderHeadService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询workOrder")
    @ApiOperation("查询workOrder")
    @PreAuthorize("@el.check('workOrderHead:list')")
    public ResponseEntity<Object> queryWorkOrderHead(WorkOrderHeadQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(workOrderHeadService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增workOrder")
    @ApiOperation("新增workOrder")
    @PreAuthorize("@el.check('workOrderHead:add')")
    public ResponseEntity<Object> createWorkOrderHead(@Validated @RequestBody WorkOrderHead resources){
        return new ResponseEntity<>(workOrderHeadService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改workOrder")
    @ApiOperation("修改workOrder")
    @PreAuthorize("@el.check('workOrderHead:edit')")
    public ResponseEntity<Object> updateWorkOrderHead(@Validated @RequestBody WorkOrderHead resources){
        workOrderHeadService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除workOrder")
    @ApiOperation("删除workOrder")
    @PreAuthorize("@el.check('workOrderHead:del')")
    public ResponseEntity<Object> deleteWorkOrderHead(@RequestBody String[] ids) {
        workOrderHeadService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}